package portal.manager.tracker;

import java.util.logging.Logger;

import org.bsc.bean.osgi.BeanManagerService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

import portal.manager.data.Page;
import portal.manager.data.PageBeanInfo;
import portal.manager.data.PageVariableBeanInfo;
import portal.manager.data.Template;
import portal.manager.data.TemplateBeanInfo;
import portal.manager.data.template.TemplateVariableEx;
import portal.manager.data.template.TemplateVariableExBeanInfo;

/**
 * 
 * @author Sorrentino
 *
 */
public class BeanManagerTracker extends ServiceTracker {
	private final Logger logger = Logger.getLogger("portal.manager");

	/**
	 * 
	 * @param context
	 */
	public BeanManagerTracker( BundleContext context) {
		super( context, BeanManagerService.class.getName(), null );

	}

	
	/**
	 * 
	 */
	@SuppressWarnings("unchecked")
	public Object addingService(ServiceReference sr) {
		logger.entering(getClass().getName(), "addingService");
		
		BeanManagerService bm = (BeanManagerService)super.addingService(sr);

		bm.registerBeanManager(Page.class, new PageBeanInfo());
		bm.registerBeanManager(Page.Variable.class, new PageVariableBeanInfo());

		bm.registerBeanManager(Template.class, new TemplateBeanInfo());
		bm.registerBeanManager(TemplateVariableEx.class, new TemplateVariableExBeanInfo());

		return bm;
	}

	/**
	 * 
	 */
	public void modifiedService(ServiceReference sr, Object service) {
	}

	/**
	 * 
	 */
	public void removedService(ServiceReference sr, Object service) {
	}

}
